//
//  WHUserStatusModel.swift
//  8.31-WH微博
//
//  Created by 吴涵 on 15/9/10.
//  Copyright © 2015年 wuhan. All rights reserved.
//

import UIKit

let WHNormalCellID = "WHCellID"

let WHForwardCellID = "WHForwardCellID"

class WHUserStatusModel: NSObject {
    /// 微博对象模型
    var status: WHStatus
    /// 当前的对应行高
    var rowHeight: CGFloat = 0
    ///拼接被转发微博的文字，
    var forwardText: String? {
    let username = status.retweeted_status?.user?.name ?? ""
        let text = status.retweeted_status?.text ?? ""
        return "@\(username):\(text)"
    }
    
    var cellID: String {
        return status.retweeted_status == nil ? WHNormalCellID : WHForwardCellID
    
    }
    /// 头像字符串转换成NSURL
    var userIconUrl: NSURL?{
    return NSURL(string: status.user?.profile_image_url ?? "")
    }
    var userVipImage: UIImage? {
        switch (status.user?.verified ?? -1){
        case 0 : return UIImage(named: "avatar_vip")
        case 2, 3, 5: return UIImage(named: "avatar_enterprise_vip")
        case 220: return UIImage(named: "avatar_grassroot")
        default: return nil
        }
    }
    var userMemberImage: UIImage? {
        if status.user?.mbrank > 0 && status.user?.mbrank < 7{
        return UIImage(named: "common_icon_membership_level\(status.user!.mbrank)")
        }
        return nil
    }
    //配图缩略图URL数组
//    "thumbnail_pic
    var thumbnailURLs: [NSURL]?
    init(status: WHStatus) {
        self.status = status
        /// 重构转发微博的给数组添加图片地址
        if let urlStrings = status.retweeted_status?.pic_urls ??  status.pic_urls{
            thumbnailURLs = [NSURL]()
            for dict in urlStrings {
                thumbnailURLs?.append(NSURL(string: dict["thumbnail_pic"]!)!)
                
            }

        }
        super.init()
    }
    override var description: String {
    return status.description + "缩略图URL数组 \(thumbnailURLs)"
    }
    

}
